//
//  main.swift
//  Begin
//
//  Created by Aries Eri on 2025/7/25.
//

import Foundation

//print("Hello, World!")
//
//print("Hello, swift!")
//
//var 🐱 = "cat"
//print(🐱)
//var a = true
//print(type(of: a))
//
//print(1, 2, 3, "no", "false", separator: "-", terminator: " ")
//print("yes")

//var text0 = """
//你好
//今天
//吃了吗?
//"""
//print(text0)
//
//var text1 = """
//你好\
//今天\
//吃了吗?
//"""
//print(text1)
//
//var text2 = #" "她今天吃的'🍌'" "#
//print(text2)

//var text3 = "Bob"
//print(text3.isEmpty)
//var len = text3.count
//print(len)
//
//var age = 18
//print("\(text3) is \(age) years old.")

//var str0 = "ABC超市😅"
//var str1 = "Hello"
//print(str0[str0.index(before: str0.endIndex)])
//print(str0[str0.index(str0.startIndex, offsetBy: 5)])

//var a:Int
//a = 20
//print(a)
//
//var b = 12341_230_1000
//print(b)
//
//var c = Int("123") ?? 0
//print(c)
//
//var d = Int("aa", radix: 16) ?? 0
//print(d)

//var a = Int.random(in: 1...100)
//print(a)

//var value = readLine() ?? "0.0"
//var radius:Double = 0.0
//radius = Double(value) ?? 0.0
//print(radius)

//var a1 = [1, 2, 3, 4]
//var a2:[Int] = [1, 2, 3]
//var a3:Array<Int> = [1, 2 ,3]
//var a4 = Array<Int>()
//var a5 = Array<Int>([1, 2, 3])
//var a6 = Array(1...10)
//var a7 = Array(repeating: "*", count: 6)
//
//print(a1[0])
//print(a1[...1])
//print(a1[0...])
//
//for e in a1 {
//    print(e, terminator: " ")
//}
//
//for (i, item) in a1.enumerated() {
//    print(i, item, separator: " ")
//}

var fruit = ["apple", "banana", "peach"]
//fruit.append("pear")
//fruit.append(contentsOf: ["Orange", "Grape", "Watermelon"])
//fruit += ["🍌"]
//
//fruit.insert("yes", at: 1)
//fruit.insert(contentsOf: ["a", "b"], at: 0)
//
//fruit.replaceSubrange(0...1, with: ["c"])
//fruit += ["d", "e"]
//print(fruit)
// fruit.contains("apple")
var isApple = fruit.first(where: {$0 == "apple"})
//print(isApple ?? "")

//fruit.remove(at: 0) // 删除指定索引
//fruit.removeFirst() // 删除头
//fruit.removeLast()  // 删除尾部
//fruit.removeAll()   // 清空

var arr = Array(1...10)
//var istwo = arr.contains(arr)
//var n1 = arr.first(where: {$0 > 3})
//var n1Index = arr.firstIndex(where: {n in n > 3})
//print(n1 ?? "")
//print(n1Index ?? "")

//var names = ["Aries", "Eri", "Bob"]
//var nameSupper = names.map{item in
//    item.uppercased()
//}
//nameSupper.forEach{item in
//    print(item)
//}
//
//names.shuffle()
//
//var na1 = names.reversed()
//names.reverse()
//
//let line = "you are so handsome."
//var ll1 = line.split(separator: " ")
//var ll2 = line.split(whereSeparator: {c in
//    c == " " || c == "."
//})
//print(ll2)
//
//print(names.joined())
//print(names.joined(separator: "-"))


//var a = Set(["apple", "banana", "peach"])
//var b = Set(["apple"])
//
//var(c, d) = a.insert("apple") // false apple
//// a.update(with: "苹果") // 无返回值
//
//print(a.union(b)) // 加
//print(a.subtracting(b)) // 减
//print(a.intersection(b)) // 交
//print(a.symmetricDifference(b)) // 加-交
//
//print(b.isSubset(of: a)) // 子集
//print(a.isSuperset(of: b)) // 超集

//var a:Dictionary<String, Int> = ["aplle":3, "banana":10]
//var b = ["hello":14, "yes":8]
//
//for(k, v) in a {
//    print(k, v)
//}
//
//for k in a.keys {
//    print(k)
//}
//
//for v in a.values {
//    print(v)
//}
//
//a.forEach{k, v in
//    print(k, v)
//}

//var a = 1.0...5.0
//for i in stride(from:1.0, through:5.0, by:1.0){
//    print(i)
//}
//let start = 1.0
//let end = 5.0
//let step = 1.0 // 明确指定步长
//
//for i in stride(from: 1.0, through: 5.0, by: 1.0) {
//    print(i)
//}

//var a = (1, 2)
//print(type(of: a))
//
//var student = (name:"Aries", age:18, id:"202211080501")
//student.name = "Bob"
//
//// 解包
//let (x, y, z) = student
//print(x, y, z)
//
//let (p, _, _) = student
//print(p)

//for i in stride(from: 0, through: 5, by: 1) {
//    print(i)
//}
//
//var index = 0
//while index < 10 {
//    print(index)
//    index += 1
//}
//// 相当于do..while
//repeat {
//    print(index)
//    index += 1
//} while index < 12

//var score = 60
//switch score {
//case 60...75:
//    print("中")
//case 76...85:
//    print("良")
//case 86...100:
//    print("优")
//default:
//    print("不及格")
//}
//
//switch score {
//case let s where s > 85:
//    print("优")
//case let s where s > 75:
//    print("良")
//case let s where s >= 60:
//    print("中")
//default:
//    print("不及格")
//}

//var p = (1, 2)
//switch p {
//case (0, 0):
//    print("位于原点")
//case (let x, 0):
//    print("位于x轴\(x)处")
//case (0, let y):
//    print("位于y轴\(y)处")
//case (let x, let y):
//    print("位于(\(x),\(y))处")
//}

//func max(a:Int, b:Int) -> Int {
//    if(a > b) {
//        return a
//    }
//    if(b > a) {
//        return b
//    }
//    return a
//}
//
//func sum(n num:Int...) -> Int {
//    var ret = 0
//    for i in num {
//        ret += i
//    }
//    return ret
//}
//
//print(max(10, 20))
//print(sum(n: 1, 2, 3, 4, 5))
//
//func out(n: inout Int) {
//    n += 1
//}
//var a = 0
//out(n: &a)
//print(a)

//enum weather:Int {
//    case sunny = 10
//    case cloudy
//    case rainy
//    
//    var description: String {
//        switch self {
//        case .sunny:
//            return "晴天"
//        case .cloudy:
//            return "阴天"
//        case .rainy:
//            return "下雨"
//        }
//    }
//}
//
//print(weather.sunny.description)

func read(book:String) -> () -> Void {
    print("我读过\(book)")
    var cnt = 0;
    return {
        cnt += 1
        print("第\(cnt)次读\(book)")
    }
}

let r = read(book: "红楼梦")
r()
r()
r()

